#include "mainviewimpl.h"

CMainViewImpl::CMainViewImpl(void)
{

}
CMainViewImpl::~CMainViewImpl(void)
{
	logi("CMainViewImpl::~CMainViewImpl");
}
std_method_impl CMainViewImpl::Init(int Argc, basic_tchar* Argv[], IBase* pRot, IBase* pBase)
{
	HRESULT	hr = S_OK;
	rc_assert(pRot != NULL, E_FAIL)
	return pRot->QueryInterface(IID_IComRotMessage, (void**)&m_pRot);
}
std_method_impl CMainViewImpl::Uninit()
{
	HRESULT		hr = S_OK;

	return hr;
}
std_method_impl CMainViewImpl::Start(_pinstance hInstance, UINT uType)
{
	HRESULT		hr = S_OK;

	hr = m_pRot->GetObject(CLSID_IUIbase, IID_IUIBase, (IBase**)&m_pIUiBase);
	rc_assert(hr == S_OK, E_FAIL)
	rc_assert(m_pIUiBase.m_p != INULL, E_FAIL)
		
	hr = m_pRot->GetObject(CLSID_ILogs, IID_ILogs, (IBase**)&m_pILogs);
	rc_assert(hr == S_OK, E_FAIL)
	rc_assert(m_pILogs.m_p != INULL, E_FAIL)

	hr = m_pIUiBase->CreateControl(UI_MESSAGELOOP, (IBase**)&m_pIUiMessageLoop);
	rc_assert(hr == S_OK, E_FAIL)

	hr = m_pIUiBase->CreateControl(UI_WINDOWS, (IBase**)&m_pIUiWindow);
	rc_assert(hr == S_OK, E_FAIL)

	basic_tchar szPath[MAX_PATH + 1] = { 0x00 };
	GetExecutePath(INSNULL, szPath, MAX_PATH);

	basic_tstring strResFile(szPath);

	//strResFile = _T("C:\\app\\duilib\\bin\\");
	strResFile += _T("//res");
	hr = m_pIUiWindow->SetResource(INSNULL, strResFile.c_str());
	rc_assert(hr == S_OK, E_FAIL)

	BasePtr pBase;
	this->QueryInterface(IID_IBase, (void**)&pBase);

	m_pIUiWindow->BindEvent(pBase);

	hr = m_pIUiWindow->SetResourceFile(_T("main.xml"));
	rc_assert(hr == S_OK, E_FAIL)

	m_pIUiWindow->CreateUiWindow(NULL);

	hr = m_pIUiMessageLoop->Add(m_pIUiWindow);
	rc_assert(hr == S_OK, E_FAIL)

	hr = m_pIUiMessageLoop->MessageLoop();
	rc_assert(hr == S_OK, E_FAIL)

	hr = m_pIUiWindow->UnBindEvent();
	rc_assert(hr == S_OK, E_FAIL)

	return hr;
}
std_method_impl CMainViewImpl::Stop(UINT uExitCode)
{
	HRESULT		hr = S_OK;

	return hr;
}
std_method_impl CMainViewImpl::Send(REFCLSID sn, REFCLSID tn, UINT msg, IBase* pInMsg, IBase* pOutMsg)
{
	HRESULT		hr = S_OK;

	return hr;
}
std_method_impl CMainViewImpl::Recv(REFCLSID sn, REFCLSID tn, UINT msg, IBase* pInMsg, IBase* pOutMsg)
{
	HRESULT		hr = S_OK;

	return hr;
}
std_method_impl CMainViewImpl::Push(REFCLSID sn, REFCLSID tn, UINT msg, IBase* pMsg)
{
	HRESULT		hr = S_OK;

	return hr;
}
std_method_impl CMainViewImpl::Poll(REFCLSID sn, REFCLSID tn, UINT msg, IBase* pMsg)
{
	HRESULT		hr = S_OK;

	return hr;
}
std_method_type_impl(ULONG) CMainViewImpl::GetRoute()
{
	return 0;
}
std_method_type_impl(ULONG) CMainViewImpl::GetSub()
{
	return 0;
}
std_method_impl CMainViewImpl::Set(ULONG ad)
{
	return S_OK;
}

std_method_impl CMainViewImpl::OnUiEvent(const NotifyEvent* event)
{
	string strMsg = "hello,world";


	const char* pCode = "{\
		\"table\": \"notify\",\
		\"count\":111,\
		\"cpu\": \"90%\",\
		\"mem\": \"50\",\
		\"acount\":2222}";

	//const char* pCode = "{\
	//	\"fix\": 111,\
	//	\"handle\": 121,\
	//	\"table\": \"scan_virus\",\
	//	\"scan_virus\": \"trojan\",\
	//	\"scan_md5\":\"aaa\"}";


	m_pILogs->PostLog((unsigned char*)pCode, s_strlen(pCode));
	return S_OK;
}

